var t = getApp();

Component({
  properties: {
    goods_info: {
      type: null
    },
    end_time_team: {
      type: null
    },
    gooddatas: {
      type: null
    },
    goodsType: {
      type: null
    },
    store_id: {
      type: null
    },
    activityId: {
      type: null
    },
    fight_groups: {
      type: null
    },
    is_o2o: {
      type: null
    },
    team: {
      type: null
    }
  },
  lifetimes: {
    attached: function (t) {
      var a = wx.getStorageSync("langIndex"),
        o = new Date().getTime() / 1e3;
      this.setData({
        nowTime: o,
        language: a.en
      });
    }
  },
  observers: {
    "gooddatas.fight_groups_number_show": function (t) {
      console.log(this.data.gooddatas, "9999999999"), "1" == t && this.totalGetTeamList();
    },
    "goods_info,goodsType": function (t, a) {
      this.setData({
        goodsInfo: "group_goods" == a || "ywmGroup" == a ? t : t.get_goods,
        goods_plugin: t.plugin
      }), t.plugin && (t.plugin.selfbuy_discount && this.setData({
        selfbuy_discount: t.plugin.selfbuy_discount
      }), t.plugin.pack_fixed_price && t.plugin.pack_fixed_price.id && this.setData({
        pack_price: t.plugin.pack_fixed_price.pack_price ? t.plugin.pack_fixed_price.pack_price : "",
        goods_count: t.plugin.pack_fixed_price.goods_count ? t.plugin.pack_fixed_price.goods_count : "",
        fixId: t.plugin.pack_fixed_price.id ? t.plugin.pack_fixed_price.id : "",
        hasActivity: !0
      }), t.plugin.prdocut_market && this.setData({
        is_market: !0,
        prdocut_market: t.plugin.prdocut_market,
        prdocut_market_name: t.plugin.prdocut_market.plugin,
        prdocut_market_name_apps: t.plugin.prdocut_market.apps
      })), t.get_goods && this.init(t.get_goods), "group_goods" != this.data.goodsType && "ywmGroup" != this.data.goodsType || this.getTeamList();
    }
  },
  data: {
    teamLis: [],
    selfbuy_discount: null,
    firstActivityBtn: "",
    firstActivityCon: "",
    activityArr: [],
    goods_plugin: [],
    goodsInfo: [],
    gooddatas: [],
    nowTime: "",
    activityShow: !1,
    popupModeshow: !0,
    show2: !1,
    show3: !1,
    teamInfo: {
      newword: !1,
      totalPage: 0,
      count: 0,
      page: 1,
      listData: []
    },
    uid: wx.getStorageSync("yz_uid"),
    language: "",
    hasActivity: !1,
    marketShow: !1,
    optionObj: {
      title: "",
      total: ""
    },
    groupTotal: {
      page: 1,
      last_page: 1,
      listData: []
    },
    showTotal: !1,
    success_team_number: 0,
    open_team_number: 0
  },
  methods: {
    formatIntergel: function (value) {
      const str = value;
      console.log(str, 'str')
      const newStr = str.replace("积分", "换货值");
      return newStr
      console.log(newStr);
    },
    init: function (a) {
      console.log('inittttttt')
      if (a.goods_sale && 0 != a.goods_sale.sale_count) {
        for (var o = 0; o < a.goods_sale.sale.length; o++) "array" == a.goods_sale.sale[o].type && a.goods_sale.sale[o].value && a.goods_sale.sale[o].value.constructor === Array && (a.goods_sale.sale[o].value = a.goods_sale.sale[o].value.join("；"));
        let arr = a.goods_sale.sale
       
        this.setData({
          activitySwitch: !0,
          activityArr: arr
        });
      } else this.setData({
        activitySwitch: !1
      });
      var e;
      1 == this.data.goods_info.get_goods.has_option && (t._isTextEmpty(this.data.optionObj.title) || t._isTextEmpty(this.data.optionObj.total)) && (this.data.goods_info.min_buy_num > 1 ? this.data.goods_info.min_buy_num > this.data.goods_info.get_goods.has_many_options[0].stock ? this.data.optionObj.total = this.data.goods_info.get_goods.has_many_options[0].stock : this.data.optionObj.total = this.data.goods_info.min_buy_num : this.data.optionObj.total = 1,
        this.data.optionObj.title = null === (e = this.data.goods_info.get_goods.has_many_options[0]) || void 0 === e ? void 0 : e.title,
        this.setData({
          optionObj: this.data.optionObj
        }));
    },
    activityShowFun: function () {
      this.triggerEvent("showCanSelf", !1), this.setData({
        activityShow: !0
      });
    },
    activityShowBtn: function () {
      this.triggerEvent("showCanSelf", !0), this.setData({
        activityShow: !1
      });
    },
    gotoList: function () {
      wx.navigateTo({
        url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + this.data.goodsInfo.store_goods.store_id
      });
    },
    gotohuiyuan: function () {
      this.data.selfbuy_discount && this.data.selfbuy_discount.link_to_level_page && 1 == this.data.selfbuy_discount.link_to_level_page.show && wx.navigateTo({
        url: "/packageB/member/MemberGradeList/MemberGradeList"
      });
    },
    toFixedPrice: function () {
      wx.navigateTo({
        url: "/packageE/others/fixedPrice/fixedPrice?id=" + this.data.fixId
      });
    },
    marketShowTap: function (t) {
      this.setData({
        marketShow: !0
      });
    },
    closeMarketShow: function () {
      this.setData({
        marketShow: !1
      });
    },
    toLink: function (t) {
      var a = t.currentTarget.dataset.item;
      a.min_link && wx.navigateTo({
        url: a.min_link
      });
    },
    showCan: function () {
      this.setData({
        showCs: !0,
        second_content: this.data.goodsInfo.has_many_params
      });
    },
    closeCs: function () {
      this.setData({
        showCs: !1
      });
    },
    showGroupMore: function () {
      if (this.data.goodsInfo && this.data.goodsInfo.vip_level_status && 1 == this.data.goodsInfo.vip_level_status.status) return wx.showToast({
        icon: "none",
        title: this.data.goodsInfo.vip_level_status.tips,
        duration: 1500
      }), !1;
      var t = ["0", "1", "2"],
        a = this.data.teamInfo.listData;
      if ("groupwork" == this.data.goodsType && (a = this.data.gooddatas.alliance, t = ["1", "2", "3"]),
        "grabGroup" == this.data.goodsType) return 0 == this.data.team.length ? void wx.showToast({
        icon: "none",
        title: "抱歉，暂无更多可参与的团!",
        duration: 2500
      }) : void this.setData({
        show3: !0
      });
      if (this.data.gooddatas.status == t[1]) {
        if ("groupwork" == this.data.goodsType) return 0 == a.length ? void wx.showToast({
          title: "暂无更多可参与的团",
          icon: "none",
          duration: 2500
        }) : void this.setData({
          show4: !0
        });
        0 == this.data.teamInfo.newword ? (this.data.teamInfo.newword = !0, this.data.teamInfo.listData.length > 0 ? this.setData({
          show2: !0
        }) : wx.showToast({
          title: "暂无更多可参与的团",
          icon: "none"
        })) : 1 == this.data.teamInfo.newword && 0 == this.data.teamInfo.listData.length ? wx.showToast({
          title: "暂无更多可参与的团",
          icon: "none",
          duration: 2500
        }) : this.setData({
          show2: !0
        });
      } else this.data.gooddatas.status == t[0] ? wx.showToast({
        title: "活动未开始",
        icon: "none",
        duration: 2500
      }) : this.data.gooddatas.status == t[2] && wx.showToast({
        title: "活动已结束",
        icon: "none",
        duration: 2500
      });
    },
    groupTotalTap: function (t) {
      "close" != t.currentTarget.dataset.key ? this.setData({
        showTotal: !0
      }) : this.setData({
        showTotal: !1
      });
    },
    totalGetTeamList: function () {
      var a = this,
        o = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
      o && this.setData({
        page: this.data.page + 1
      });
      var e = t.getNetAddresss("plugin.fight-groups.frontend.controllers.fight-groups-goods.all-join-team-number"),
        s = {
          id: this.data.gooddatas.id,
          page: this.data.page
        };
      t._getNetWork({
        url: e,
        data: s,
        success: function (t) {
          var e = t.data;
          1 == e.result && (o ? a.setData({
            "groupTotal.last_page": e.data.team_member.last_page,
            "groupTotal.listData": a.data.groupTotal.listData.concat(e.data.team_member.data)
          }) : a.setData({
            success_team_number: e.data.success_team_number,
            open_team_number: e.data.open_team_number,
            "groupTotal.last_page": e.data.team_member.last_page,
            "groupTotal.listData": e.data.team_member.data
          }));
        }
      });
    },
    getTeamList: function () {
      var a = this,
        o = "fight-groups";
      "ywmGroup" == this.data.goodsType && (o = "ywm-fight-groups");
      var e = t.getNetAddresss("plugin.".concat(o, ".frontend.controllers.fight-groups-goods.all-team")),
        s = this.data.store_id;
      s && 0 != s && "undefined" != s && (e = t.getNetAddresss("plugin.fight-groups.frontend.store.frontend-fight-groups-goods.all-team"),
          e += "&store_id=" + s), "undefined" != this.data.fight_groups ? (e += "&id=" + this.data.activityId,
          e += "&fight_groups_goods_id=" + this.data.fight_groups) : e += "&id=" + this.data.activityId,
        t._getNetWork({
          url: e,
          success: function (o) {
            var e = o.data;
            1 == e.result && (t._isTextEmpty(e.data.data) || e.data.data.map(function (a) {
              a.nowTime = new Date().getTime() / 1e3, t._isTextEmpty(a.end_time) || (a.overTime = a.end_time);
            }), a.setData({
              "teamInfo.totalPage": e.data.last_page,
              "teamInfo.total": e.data.total,
              "teamInfo.listData": e.data.data
            }));
          }
        });
    },
    tapOverlay: function () {
      "groupwork" != this.data.goodsType ? "grabGroup" != this.data.goodsType ? this.setData({
        show2: !1,
        posterShow: !1,
        showOpenGroup: !1
      }) : this.setData({
        show3: !1,
        posterShow: !1,
        showOpenGroup: !1
      }) : this.setData({
        show4: !1,
        posterShow: !1,
        showOpenGroup: !1
      });
    },
    clickAdd: function (a) {
      var o = this,
        e = a.target.dataset.id || a.currentTarget.dataset.id;
      if ("groupwork" == this.data.goodsType) wx.navigateTo({
        url: "/packageI/groupWork/groupWorkDetail/groupWorkDetail?allianceid=" + e + "&id=" + this.data.gooddatas.id
      });
      else {
        if ("grabGroup" == this.data.goodsType) return void("grabGroup" == this.data.goodsType && wx.navigateTo({
          url: "/packageE/grab_group/grab_group_detail/grab_group_detail?&id=" + e
        }));
        a.target.dataset.item || a.currentTarget.dataset.item;
        var s = a.target.dataset.id || a.currentTarget.dataset.id;
        if (this.data.goodsInfo.vip_level_status && 1 == this.data.goodsInfo.vip_level_status.status) return wx.showToast({
          icon: "none",
          title: this.data.goodsInfo.vip_level_status.tips,
          duration: 2500
        }), !1;
        var i = this,
          n = [];
        n.push(i.data.goodsId);
        var d = t.getNetAddresss("from.div-from.isDisplay");
        d += "&goods_ids=" + JSON.stringify(n), t._getNetWork({
          showToastIn: !1,
          url: d,
          success: function (t) {
            var a = t.data;
            if (1 == a.result)
              if (a.data.status && !a.data.member_status) wx.showModal({
                title: "提示",
                content: "购买此商品,请补充您的个人信息",
                success: function (t) {
                  t.confirm ? wx.navigateTo({
                    url: "/packageB/member/address/myinfo/myinfo?tag=group&activityId=" + i.data.activityId
                  }) : t.cancel && console.log("用户点击取消");
                }
              });
              else {
                var e = "/packageB/member/group/GroupDetail/GroupDetail?id=" + s + "&store_id=" + i.properties.store_id;
                "ywmGroup" == o.data.goodsType && (e += "&plu=ywm"), wx.navigateTo({
                  url: e
                });
              }
            else wx.showToast({
              icon: "none",
              title: a.msg,
              duration: 2500
            });
          },
          fail: function (t) {}
        });
      }
    },
    showPop: function (t) {
      this.triggerEvent("showPop", !0);
    },
    gophone: function (t) {
      var a = t.currentTarget.dataset.mobile;
      wx.makePhoneCall({
        phoneNumber: a
      });
    },
    goToAdress: function () {
      var a = this.data.gooddatas.store.store.latitude,
        o = this.data.gooddatas.store.store.longitude,
        e = this.data.gooddatas.store.store.store_name,
        s = t.BMapTransqqMap(parseFloat(o), parseFloat(a));
      wx.openLocation({
        latitude: s.lat,
        longitude: s.lng,
        scale: 18,
        name: e
      });
    },
    getMoreTeamList: function () {
      var a = this,
        o = "fight-groups";
      "ywmGroup" == this.data.goodsType && (o = "ywm-fight-groups");
      var e = t.getNetAddresss("plugin.".concat(o, ".frontend.controllers.fight-groups-goods.all-team"));
      this.properties.store_id && 0 != this.properties.store_id && "undefined" != this.properties.store_id && (e = t.getNetAddresss("plugin.fight-groups.frontend.store.frontend-fight-groups-goods.all-team"),
          e += "&store_id=" + this.properties.store_id), "undefined" != this.data.fight_groups ? (e += "&id=" + this.data.activityId,
          e += "&fight_groups_goods_id=" + this.data.fight_groups) : e += "&id=" + this.data.activityId,
        this.data.teamInfo.page++, e += "&page=" + this.data.teamInfo.page, t._getNetWork({
          url: e,
          success: function (o) {
            var e = o.data;
            if (1 == e.result) {
              var s = e.data.data;
              t._isTextEmpty(s) || s.map(function (a) {
                a.nowTime = new Date().getTime() / 1e3, t._isTextEmpty(a.end_time) || (a.overTime = a.end_time);
              });
              var i = a.data.teamInfo.listData.concat(s);
              a.setData({
                "teamInfo.listData": i
              });
            }
          }
        });
    },
    getBuyNow: function () {
      this.triggerEvent("contorBuyNow_good", !0);
    }
  }
});